﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ResourcesAssetFactory : IAssetFactory
{
    private string audioPath = "Audios/";
    private string campPath = "Camps/";
    private string enemyPath = "Characters/Enemy";
    private string soldierPath = "Characters/Soldier";
    private string effectPath = "Effects/";
    private string spritePath = "Sprites/";
    private string weaponPath = "Weapons/";

    public AudioClip LoadAudioClip(string name)
    {
        return   LoadAsset(audioPath + name) as AudioClip;
        
    }

    public GameObject LoadEffect(string name)
    {
        return InitiateGameObject(effectPath + name);
    }

    public GameObject LoadEnemy(string name)
    {
        return InitiateGameObject(enemyPath + name);
    }

    public GameObject LoadSoldier(string name)
    {
        return InitiateGameObject(soldierPath + name);
    }

    public Sprite LoadSprite(string name)
    {
        return LoadAsset(spritePath + name) as Sprite;
    }

    public GameObject LoadWeapon(string name)
    {
        return InitiateGameObject(weaponPath + name);
    }
    public GameObject LoadCamp(string name)
    {
        return InitiateGameObject(campPath + name);
    }
    private GameObject InitiateGameObject(string path)
    {
        UnityEngine.Object o = Resources.Load(path);
        if (o == null)
        {
            Debug.LogError("");
        }
        return GameObject.Instantiate(o) as GameObject;
    }
    
    private UnityEngine.Object LoadAsset(string path)
    {
        UnityEngine.Object o = Resources.Load(path);
        if (o == null)
        {
            Debug.LogError("");
        }
        return o;
    }
}
